<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <link rel="head.png" href="/PNG/head.png"/>
    <title>欢迎使用领捷智慧物流管理系统</title>
    <link rel="hshortcut icon" href="../static/img/own/head.png"/>
    <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i">
    <link rel="stylesheet" href="/static/fonts/fontawesome-all.min.css">
</head>

<body>
<div id="wrapper">
    <div class="d-flex flex-column" id="content-wrapper">
        <div id="content">
            <div class="container text-break text-center" style="max-width: 1547px;height: 88px;margin: 0px;margin-bottom: 30px;padding: 12px;padding-right: 24px;padding-left: 24px;padding-top: 3px;min-width: 100%;">
                <div class="card row" style="margin: 0px;">
                    <div class="card-body border rounded" style="height: 79px;min-width: 0px;padding: 24px;padding-top: 23px;margin: 0px;margin-top: 0px;width: auto;">
                        <div class="row" style="width: auto;">

                            <div class="col" style="width: auto;">
                                <div class="dropdown text-center" style="text-align: right;">
                                    <input class="form-control" type="date" style="width: 350px;margin-left: 10px;" id="createtime" name="createtime">
                                </div>
                            </div>

                            <div class="col" style="width: auto;">
                                <div class="dropdown text-center" style="text-align: right;">
                                    <input style="height: 38px" type="text" placeholder="商品号" id="goodsid" name="goodid">
                                </div>
                            </div>
                            <div class="col" style="width: auto;">
                                <div class="dropdown text-xl-center" style="text-align: right;">
                                    <input style="height: 38px" type="text" placeholder="客户手机号" id="customerphone" name="customnum">
                                </div>
                            </div>
                            <div class="col" style="width: auto;">
                                <div class="dropdown text-xl-center" style="text-align: right;">
                                    <input style="height: 38px" type="text" placeholder="单号" id="orderid" name="orderid">
                                </div>
                            </div>
                            <div class="col" style="width: auto;"align="right">
                                <div class="btn-group" role="group" style="padding-left: 1px;">
                                    <button class="btn btn-primary" type="button" id="searchOutputOrderByKeyWord">查询</button>
                                    <button class="btn btn-primary" type="button" style="margin-left: 5px;" id="clean">重置</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container-fluid">
                <div class="card shadow">
                    <div class="card-header py-3" style="height: 75px;">
                        <div class="row" style="width: auto;height: auto;">
                            <div class="col">
                                <div class="btn-group" role="group">
                                    <button class="btn btn-primary" type="button" style="width: 120px;" id="addOutputOrder">新增</button>
                                    <button class="btn btn-primary" type="button" style="margin-left: 5px;width: 120px;" id="deleteOrder">删除</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive table mt-2" id="dataTable-1" role="grid" aria-describedby="dataTable_info">
                            <table class="table my-0" id="dataTable">
                                <thead style="height: 71px;">

                                <tr style="height: 60px;text-align: center">
                                    <th style="width: 100px;height: 60px;"><input type="checkbox" style="margin-left: 1px;" id="selectAll">订单号</th>
                                    <th style="width: auto;text-align: center;">创建日期</th>
                                    <th>商品号</th>
                                    <th>数量</th>
                                    <th>客户电话</th>
                                    <th>客户名称</th>
                                    <th>客户地址</th>
                                    <!--                                <th style="width: auto;text-align: center;">单价</th>-->
                                    <th style="width: auto;text-align: center;">状态</th>
                                    <th style="width: auto;text-align: center;">总价</th>
                                </tr>
                                </thead>
                                <tbody id="order" style="text-align: center">

                                </tbody>
                                <tfoot>
                                <tr></tr>
                                </tfoot>
                            </table>
                        </div>
                        <div class="row">
                            <div class="col-md-6 align-self-center">
                                <!--                        <p id="dataTable_info" class="dataTables_info" role="status" aria-live="polite">Showing 1 to 10 of 27</p>-->
                            </div>
                            <div class="col-md-6">
                                <nav class="d-lg-flex justify-content-lg-end dataTables_paginate paging_simple_numbers">
                                    <ul class="pagination">
                                        <li class="page-item disabled"><a class="page-link" href="#" aria-label="Previous"><span aria-hidden="true">«</span></a></li>
                                        <li class="page-item active"><a class="page-link" href="#">1</a></li>
                                        <li class="page-item"><a class="page-link" href="#">2</a></li>
                                        <li class="page-item"><a class="page-link" href="#">3</a></li>
                                        <li class="page-item"><a class="page-link" href="#" aria-label="Next"><span aria-hidden="true">»</span></a></li>
                                    </ul>
                                </nav>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <footer class="bg-white sticky-footer">
            <div class="container my-auto">
                <div class="text-center my-auto copyright"><span>鄂ICP备2021022432号</span></div>
            </div>
        </footer>
    </div><a class="border rounded d-inline scroll-to-top" href="#page-top"><i class="fas fa-angle-up"></i></a></div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/js/chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.js"></script>
<script src="/static/js/script.min.js"></script>
<script src="/static/js/jquery.session.js"></script>

<script>
    // 初始化页面
    $(document).ready(function (){
        $.ajax({
            url: "/order/allOutputOrder",
            type: 'post',
            dataType:"json",
            success:function (result){
                let str = "";
                for(let i = 0; i < result.length; i++){
                    if(result[i].state == 0){
                        var state = "待出库";
                    }else if(result[i].state == 1){
                        var state = "已出库";
                    }else if(result[i].state == 2){
                        var state = "已发货";
                    }
                    str +="<tr><td  class=\"checkOrderId\"><input type=\"checkbox\" style=\"margin-left: 1px;\" class=\"checkOne\" name=\"checkbox\">" + result[i].orderid +"</td>" +
                        "<td>" + result[i].createtime + "</td>" +
                        "<td>" + result[i].goodsid + "</td>" +
                        "<td>" + result[i].num + "</td>" +
                        "<td>" + result[i].customerphone + "</td>" +
                        "<td>" + result[i].customername + "</td>" +
                        "<td>" + result[i].customeradd + "</td>" +
                        "<td>" + state + "</td>" +
                        "<td>" + result[i].totalprice + "</td></tr>"
                }
                $("#order").append(str);
            }
        })
    })


    // 跳转添加订单
    $(function (){
        $("#addOutputOrder").click(function (){
            $(location).attr("href","/page/toAddOutputOrder")
        })
    })

    ////根据订单号、商品号、顾客手机号搜索订单
    $(function (){
        $("#searchOutputOrderByKeyWord").on("click",function (){
            var createtime = $("#createtime").val();
            var orderid = $("#orderid").val();
            var goodsid = $("#goodsid").val();
            var customerphone = $("#customerphone").val();
            $.ajax({
                url: "/order/searchOutputOrderByKeyWord",
                type: 'post',
                data: {"createtime":createtime, "orderid": orderid,"goodsid": goodsid, "customerphone":customerphone},
                dataType:"json",
                success:function (result){
                    $("#order").html("");
                    let str = "";
                    for(let i = 0; i < result.length; i++){
                        if(result[i].state == 0){
                            var state = "待出库";
                        }else if(result[i].state == 1){
                            var state = "已出库";
                        }else if(result[i].state == 2){
                            var state = "已发货";
                        }
                        str +="<tr><td  class=\"checkOrderId\"><input type=\"checkbox\" style=\"margin-left: 1px;\" class=\"checkOne\" name=\"checkbox\">" + result[i].orderid +"</td>" +
                            "<td>" + result[i].createtime + "</td>" +
                            "<td>" + result[i].goodsid + "</td>" +
                            "<td>" + result[i].num + "</td>" +
                            "<td>" + result[i].customerphone + "</td>" +
                            "<td>" + result[i].customername + "</td>" +
                            "<td>" + result[i].customeradd + "</td>" +
                            "<td>" + state + "</td>" +
                            "<td>" + result[i].totalprice + "</td></tr>"
                    }
                    $("#order").append(str);
                }
            })
        })
    })

    //清空搜索框
    $(function (){
        $("#clean").on("click",function (){
            $(location).attr("href","/page/toOrder")
        })
    })

    //全选复选框
    $(function (){
        $("#selectAll").on("click",function (){
            var selectAll = document.getElementById("selectAll");
            // alert(selectAll.checked);
            if(selectAll.checked == true){
                var checkOnes = document.getElementsByClassName("checkOne");
                for(var i=0;i<checkOnes.length;i++){
                    checkOnes[i].checked=true;
                }
            }else{
                var checkOnes = document.getElementsByClassName("checkOne");
                for(var i=0;i<checkOnes.length;i++){
                    checkOnes[i].checked=false;
                }
            }
        })
    })

    //根据复选框删除订单
    $(function (){
        $("#deleteOrder").on("click",function (){
            var checkOnes = document.getElementsByClassName("checkOne");

            var obj = [];
            var k = 0;
            for(var i = 0;i < checkOnes.length;i++){
                if(checkOnes[i].checked){
                    // var id = $(".checkOrderId").parent('tr').children().eq(0).text();
                    let id = $(".checkOrderId").eq(i).text();
                    // alert(id);
                    obj[k++]=id;
                }
            }
            // alert(obj);
            if(obj.length !== 0){

                if(window.confirm("确认删除吗？")){
                    $.ajax({
                        url: "/order/deleteOutputOrder",
                        type: 'post',
                        dataType:"json",
                        data: {obj:obj},
                        traditional:true,
                        success:function (result){
                            alert("删除成功！");
                            $(location).attr("href","/page/toOrder");
                        }
                    })
                }else{

                }
            }else{
                alert("请选择条目!");
            }


        })
    })

    //session
    $.session.set("url",window.location.href);

</script>

</body>

</html>